import { TTenantType } from '@/datatypes/tTenant/data';
import {ProFormSelect, ProFormText, StepsForm} from '@ant-design/pro-components';
import { Modal } from 'antd';
import React from 'react';
import {UserStatusValueEnum} from "@/enums/auth";

export type FormValueType = {
  target?: string;
  template?: string;
  type?: string;
  time?: string;
  frequency?: string;
} & Partial<TTenantType>;

export type UpdateFormProps = {
  onCancel: (flag?: boolean, formVals?: FormValueType) => void;
  onSubmit: (values: FormValueType) => Promise<void>;
  updateModalVisible: boolean;
  values: Partial<TTenantType>;
};

const UpdateForm: React.FC<UpdateFormProps> = (props) => {
  return (
    <StepsForm
      stepsProps={{
        size: 'small',
      }}
      stepsFormRender={(dom, submitter) => {
        return (
          <Modal
            width={640}
            style={{
              padding: '32px 40px 48px',
            }}
            destroyOnClose
            title="更新"
            open={props.updateModalVisible}
            footer={submitter}
            onCancel={() => {
              props.onCancel();
            }}
          >
            {dom}
          </Modal>
        );
      }}
      onFinish={props.onSubmit}
    >
      <StepsForm.StepForm
        initialValues={{
          phone: props.values.phone,
          remark: props.values.remark,
          status: props.values.status,
          name: props.values.name,
        }}
        title="基本信息"
      >
        <ProFormText
          rules={[
            {
              required: true,
              message: '租户名为必填项',
            },
          ]}
          width="md"
          name="name"
          label={'租户名'}
          placeholder={'请输入租户名'}
        />
        <ProFormText
          rules={[
            {
              required: true,
              message: '电话为必填项',
            },
          ]}
          width="md"
          name="phone"
          label={'电话'}
          placeholder={'请输入电话'}
        />

        <ProFormText
          rules={[
            {
              required: true,
              message: '用户备注为必填项',
            },
          ]}
          width="md"
          name="remark"
          label={'用户备注'}
          placeholder={'请输入用户备注'}
        />

        <ProFormSelect
          rules={[
            {
              required: true,
              message: '用户状态',
            },
          ]}
          width="md"
          name="status"
          label={'用户状态'}
          valueEnum={UserStatusValueEnum}
          placeholder={'请输入用户状态'}
        />
      </StepsForm.StepForm>
    </StepsForm>
  );
};

export default UpdateForm;
